]> dgit.raspbian.org Git - gnome-shell.git/commitdiff
dash: Move getAppFromSource() into static method
authorFlorian Müllner <fmuellner@gnome.org>
Sat, 19 Aug 2023 16:31:24 +0000 (18:31 +0200)
committerMarge Bot <marge-bot@gnome.org>
Sun, 20 Aug 2023 01:30:55 +0000 (01:30 +0000)
This is a small helper function that is used by the DND handling
in the dash and its items.

It turns out that some extensions used to override it, which is
no longer possible: We don't export it, and if we did, it would
be read-only.

To make the function available again, expose it as static method
on the dash itself.

Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/2903>

js/ui/dash.js

index 7f09e65e14242743c263ffb18abaf98cce74c1f8..0841b6c047c05a2544577d9f16eb00215297b5e2 100644 (file)
@@ -20,16 +20,6 @@ const DASH_ITEM_LABEL_SHOW_TIME = 150;
 const DASH_ITEM_LABEL_HIDE_TIME = 100;
 const DASH_ITEM_HOVER_TIMEOUT = 300;
 
-/**
- * @param {AppDisplay.AppIcon} source
- */
-function getAppFromSource(source) {
-    if (source instanceof AppDisplay.AppIcon)
-        return source.app;
-    else
-        return null;
-}
-
 export const DashIcon = GObject.registerClass(
 class DashIcon extends AppDisplay.AppIcon {
     _init(app) {
@@ -263,14 +253,14 @@ class ShowAppsIcon extends DashItemContainer {
     }
 
     handleDragOver(source, _actor, _x, _y, _time) {
-        if (!this._canRemoveApp(getAppFromSource(source)))
+        if (!this._canRemoveApp(Dash.getAppFromSource(source)))
             return DND.DragMotionResult.NO_DROP;
 
         return DND.DragMotionResult.MOVE_DROP;
     }
 
     acceptDrop(source, _actor, _x, _y, _time) {
-        let app = getAppFromSource(source);
+        const app = Dash.getAppFromSource(source);
         if (!this._canRemoveApp(app))
             return false;
 
@@ -321,6 +311,16 @@ const baseIconSizes = [16, 22, 24, 32, 48, 64];
 export const Dash = GObject.registerClass({
     Signals: {'icon-size-changed': {}},
 }, class Dash extends St.Widget {
+    /**
+     * @param {object} source
+     */
+    static getAppFromSource(source) {
+        if (source instanceof AppDisplay.AppIcon)
+            return source.app;
+        else
+            return null;
+    }
+
     _init() {
         this._maxWidth = -1;
         this._maxHeight = -1;
@@ -444,7 +444,7 @@ export const Dash = GObject.registerClass({
     }
 
     _onItemDragMotion(dragEvent) {
-        let app = getAppFromSource(dragEvent.source);
+        const app = Dash.getAppFromSource(dragEvent.source);
         if (app == null)
             return DND.DragMotionResult.CONTINUE;
 
@@ -860,7 +860,7 @@ export const Dash = GObject.registerClass({
     }
 
     handleDragOver(source, actor, x, _y, _time) {
-        let app = getAppFromSource(source);
+        const app = Dash.getAppFromSource(source);
 
         // Don't allow favoriting of transient apps
         if (app == null || app.is_window_backed())
@@ -947,7 +947,7 @@ export const Dash = GObject.registerClass({
 
     // Draggable target interface
     acceptDrop(source, _actor, _x, _y, _time) {
-        let app = getAppFromSource(source);
+        const app = Dash.getAppFromSource(source);
 
         // Don't allow favoriting of transient apps
         if (app == null || app.is_window_backed())